<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="商品名字" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入商品名字" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商户流水号" prop="payOrderId">
        <el-input v-model="queryParams.payOrderId" placeholder="请输入商户流水号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNumber">
        <el-input v-model="queryParams.orderNumber" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="打印状态" prop="printStatus">
        <el-select v-model="queryParams.printStatus" placeholder="请选择" clearable style="width: 180px">
          <el-option v-for="item in dylist" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="请选择" clearable style="width: 200px">
          <el-option v-for="item in zflist" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车牌号" prop="carNumber">
        <el-input v-model="queryParams.carNumber" placeholder="请输入车牌号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="支付时间">
        <el-date-picker @change="payChange($event, 1)" style="width: 240px" v-model="payTimeList"
          value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker @change="payChange($event, 2)" style="width: 240px" v-model="beginTimeList"
          value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="打印时间">
        <el-date-picker @change="payChange($event, 3)" style="width: 240px" v-model="printTimeList"
          value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:user:export']">导出</el-button>
      </el-col>
      <el-col :span="3" :xs="24" :md="6" style="display: flex; align-items: center">
        <div style="font-weight: bold; font-size: 16px">合计数量：</div>
        <div style="font-weight: bold; font-size: 16px">{{ count_sum }}</div>
      </el-col>
      <el-col :span="3" :xs="24" :md="6" style="display: flex; align-items: center">
        <div style="font-weight: bold; font-size: 16px">合计金额：</div>
        <div style="font-weight: bold; font-size: 16px">{{ amount_sum }}</div>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" width="55" align="center" prop="id" />
      <el-table-column label="订单编号" width="220" align="center" prop="orderNumber" />
      <el-table-column label="商户流水号" width="270" align="center" prop="payOrderId" />
      <el-table-column label="商品名字" width="100" align="center" prop="productName" show-overflow-tooltip />
      <el-table-column label="商品单价" align="center" prop="productPrice" />
      <el-table-column label="商品数量" align="center" prop="productCount" />
      <el-table-column label="订单总价" align="center" prop="totalAmount" />
      <el-table-column label="车牌号" width="100" align="center" prop="carNumber" />
      <el-table-column label="打印数量" align="center" prop="printCount" />
      <el-table-column label="打印状态" align="center" prop="printStatus">
        <template slot-scope="scope">
          <div>
            <span v-if="scope.row.printStatus == 0">未打印</span>
            <span v-else-if="scope.row.printStatus == 1">成功</span>
            <span v-else-if="scope.row.printStatus == 2">失败</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="打印时间" width="180" align="center" prop="printTime" />
      <el-table-column label="支付状态" align="center" prop="payStatus">
        <template slot-scope="scope">
          <div>
            <span v-if="scope.row.payStatus == 0">未支付</span>
            <span v-else>支付成功</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" width="180" align="center" prop="payTime" />
      <el-table-column label="昵称" align="center" prop="userName" show-overflow-tooltip />
      <el-table-column label="手机号" width="120" align="center" prop="userPhone" />
      <el-table-column label="创建时间" width="180" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-s-check" @click="handledy(scope.row)"
            v-hasPermi="['advertising:remove']">打印</el-button>
          <el-button :disabled="scope.row.payStatus == 0 ? false : true" size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['advertising:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import {
  getorderlist,
  orderPrint,
  orderremove,
  getTotal,
} from "@/api/system/mine/index";
import Upimg from "../../../components/UploadImg";
export default {
  name: "Post",
  dicts: ["sys_normal_disable"],
  components: { Upimg },
  data() {
    return {
      dylist: [
        {
          id: 0,
          name: "未打印",
        },
        {
          id: 1,
          name: "成功",
        },
        {
          id: 2,
          name: "失败",
        },
      ],
      zflist: [
        {
          id: 0,
          name: "未支付",
        },
        {
          id: 2,
          name: "支付成功",
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payOrderId: undefined,
        orderNumber: undefined,
        productName: undefined,
        carNumber: undefined,
        printStatus: undefined,
        payStatus: undefined,
        userPhone: undefined,
        printTimeBegin: undefined,
        printTimeEnd: undefined,
        payTimeBegin: undefined,
        payTimeEnd: undefined,
        beginTime: undefined,
        endTime: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        images: [{ required: true, message: "图片不能为空", trigger: "blur" }],
        sort: [
          { required: true, message: "轮播图顺序不能为空", trigger: "blur" },
        ],
      },
      isshow: false,
      count_sum: "",
      amount_sum: "",
      payTimeList: [],
      beginTimeList: [],
      printTimeList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    payChange(e, status) {
      if (status == 1) {
        this.queryParams.payTimeBegin = e[0];
        this.queryParams.payTimeEnd = e[1];
      } else if (status == 2) {
        this.queryParams.beginTime = e[0];
        this.queryParams.endTime = e[1];
      } else {
        this.queryParams.printTimeBegin = e[0];
        this.queryParams.printTimeEnd = e[1];
      }
    },
    /** 查询岗位列表 */
    getList() {
      getorderlist(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
        getTotal(this.queryParams).then((res) => {
          this.count_sum = res.data.count_sum;
          this.amount_sum = res.data.amount_sum;
        });
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.payTimeList = [];
      this.beginTimeList = [];
      this.printTimeList = [];
      this.queryParams.printTimeBegin = undefined;
      this.queryParams.printTimeEnd = undefined;
      this.queryParams.payTimeBegin = undefined;
      this.queryParams.payTimeEnd = undefined;
      this.queryParams.beginTime = undefined;
      this.queryParams.endTime = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handledy(row) {
      const userIds = row.id || this.ids;
      this.$modal
        .confirm('是否要打印用户编号为"' + userIds + '"的订单数据？')
        .then(function () {
          orderPrint({ id: userIds }).then((res) => {
            console.log(res);
          });
        })
        .then(() => {
          this.$modal.msgSuccess("打印成功");
          this.getList();
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "orders/export",
        {
          ...this.queryParams,
        },
        `订单管理.xlsx`
      );
    },
    handleDelete(row) {
      const userIds = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除用户编号为"' + userIds + '"的数据项？')
        .then(function () {
          orderremove({ id: userIds }).then((res) => {
            console.log(res);
          });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
  },
};
</script>
<style>
.img {
  width: 120px;
  height: 100px;
  border-radius: 10px;
}
</style>
